Micron Document
πŸŽ–οΈGitΠ―Ρ€Π°πŸŽ–οΈ


Displaying Rendered β€’ View raw β€’ Download

.specify/extensions/optimize/README.md b2a8377bbb01a5875eba4b12f6f1c7e7d9e60a91 (b2a8377b) Text, 5.25 KB

Spec-Kit Optimize Extension

Audits and optimizes AI governance documents for context efficiency. Designed for long-term AI-driven development where constitutions grow organically and accumulate token debt.

Why This Extension Exists

In AI-driven development, the constitution is loaded into every AI session's context window. Over time:

β€’ Token bloat: Rules, examples, and version history accumulate β€” costing tokens on every invocation
β€’ Rule decay: Incident-specific rules persist forever because AI has no institutional memory
β€’ Non-deterministic governance: Ambiguous rules cause different AI sessions to behave differently
β€’ Governance echoes: The same rule gets restated across multiple files, wasting tokens and risking contradictions
β€’ No learning loop: AI sessions make the same mistakes repeatedly with no mechanism to capture learnings

This extension provides tooling to detect and fix these problems.

Installation

T282828
T8b949e# From the spec-kit catalog (when published)
specify extension add optimize

T8b949e# From a direct URL
specify extension add optimize --from https://github.com/sakitA/spec-kit-optimize/archive/refs/tags/v1.0.0.zip

T8b949e# For local development
specify extension add --dev /path/to/spec-kit-optimize


Commands

T383838/speckit.optimize.run β€” Constitution Audit

Analyzes the constitution across 6 categories uniquely relevant to AI-driven development:

1. Token Budget Analysis β€” measures per-section token cost and governance density
2. Rule Health Analysis β€” detects stale, incident-specific, superseded, and graduated rules
3. AI Interpretability Analysis β€” finds ambiguity, contradictions, unenforceable rules
4. Semantic Compression β€” identifies collapsible rule clusters, redundant examples, inline-to-reference conversions
5. Constitution Coherence β€” evaluates principle balance, rule scatter, cross-references, CLAUDE.md drift
6. Governance Echo Detection β€” finds cross-file duplication and total governance token budget

T282828
T8b949e# Full audit
/speckit.optimize.run

T8b949e# Single category
/speckit.optimize.run --category token_budget

T8b949e# Report only (no apply step)
/speckit.optimize.run --report-only


T383838/speckit.optimize.tokens β€” Token Usage Tracker

Measures the token footprint of all governance files and extension commands. Tracks trends over time.

T282828
T8b949e# Full token report
/speckit.optimize.tokens

T8b949e# Compare against previous report
/speckit.optimize.tokens --diff

T8b949e# Extensions only (skip governance files)
/speckit.optimize.tokens --extensions-only


T383838/speckit.optimize.learn β€” Session Learning

End-of-session analysis: detects AI mistake patterns, repetitive corrections, and governance gaps. Suggests constitution rules or memory entries to prevent recurrence.

T282828
T8b949e# Full session analysis
/speckit.optimize.learn

T8b949e# Rules only (no memory suggestions)
/speckit.optimize.learn --rules-only

T8b949e# Analyze from a specific commit
/speckit.optimize.learn --since abc1234


Design Philosophy

Suggest-only by default. Every command produces a report first. Nothing is modified until the user explicitly approves. The flow is always: Analyze β†’ Report β†’ Propose β†’ User Consent β†’ Apply.

Spec-kit standard paths. The extension works with any spec-kit project. It uses T383838.specify/memory/constitution.md as the primary constitution path and follows redirects for project-specific layouts. It never hardcodes project-specific paths.

Semantic preservation. Optimization removes redundancy in expression, not in intent. Every governance rule survives compression β€” only its token cost changes.

Configuration

Copy T383838config-template.yml to T383838optimize-config.yml in the extension directory:

T282828
cp .specify/extensions/optimize/config-template.yml Tffea00\
.specify/extensions/optimize/optimize-config.yml


Key settings:
β€’ T383838categories.* β€” toggle individual analysis categories on/off
β€’ T383838thresholds.max_constitution_tokens β€” flag constitutions exceeding this token estimate
β€’ T383838thresholds.governance_budget_percent β€” max % of context window for governance overhead
β€’ T383838target_context_window β€” context window size for budget calculations (default: 200K)
β€’ T383838learn.min_corrections_to_flag β€” minimum repeated corrections before flagging a pattern

Integration

β€’ T383838/speckit.constitution β€” authoring tool. Optimize hands off to it for applying approved changes with proper version bumping.
β€’ T383838/speckit.analyze β€” consistency checker. Run after optimization to verify cross-artifact alignment.
β€’ T383838/speckit.optimize.tokens β†’ T383838/speckit.optimize.run β€” if token tracker reveals high governance overhead, run the full audit.
β€’ T383838/speckit.optimize.learn β†’ T383838/speckit.constitution β€” approved rules from session learning are applied via the constitution skill.

Reports

Reports are saved to T383838.specify/optimize/ (with user consent):
β€’ T383838token-report.md β€” latest token usage snapshot (enables historical trends)
β€’ T383838learning-report-<date>.md β€” per-session learning analysis

Requirements

β€’ Spec-Kit >= 0.1.0
β€’ An existing populated constitution (not a raw template)
β€’ Git repository (for learn command's session analysis)

License

MIT

Served by rngit 1.5.2 - Generated in 0.04s